package vn.com.tiz.bookcase.adapter;

import java.util.ArrayList;

import org.w3c.dom.ls.LSInput;

import vn.com.tiz.DocumentZ.R;
import vn.com.tiz.bookcase.entry.ChapterInfo;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;

public class ChapterAdapter extends BaseAdapter {
	
	private ArrayList<ChapterInfo> listChapter;
	private Context context;
	private LayoutInflater inflater;
	
	public ChapterAdapter(Context context,ArrayList<ChapterInfo> listChapter){
		this.listChapter = listChapter;
		this.context = context;
		inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	public int getCount() {
		// TODO Auto-generated method stub
		return listChapter.size();
	}

	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return null;
	}

	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		if(convertView == null)
		{
			View v = inflater.inflate(R.layout.chapter_item, null);
			TextView txvChapterIndex = (TextView)v.findViewById(R.id.txvChapterIndex);
			TextView txvChapterTitle = (TextView)v.findViewById(R.id.txvChapterTitle);
			
			ChapterInfo chapter = listChapter.get(position);			
			txvChapterIndex.setText(chapter.ChapterName+" "+chapter.ChapterIndex);
			LinearLayout lnearItem = (LinearLayout)v.findViewById(R.id.lnearItem);
			lnearItem.setOnClickListener(chapter_click);
			//v.setOnClickListener(chapter_click);
			
			//v.setLayoutParams(lp);
			convertView = v;
			
		}
		return convertView;
	}

	private OnClickListener chapter_click = new OnClickListener() {
		
		public void onClick(View v) {
			// TODO Auto-generated method stub
			Log.d("TrungTT","Chapter click...");
		}
	};
}
